package com.example.springboot.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.springboot.common.Constants;
import com.example.springboot.dto.UserDTO;
import com.example.springboot.entity.User;
import com.example.springboot.service.IUserService;
import com.example.springboot.utils.TokenUtils;
import org.apache.el.parser.Token;
import org.springframework.web.bind.annotation.*;
import com.example.springboot.common.Result;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import com.example.springboot.service.IFollowService;
import com.example.springboot.entity.Follow;

import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/follow")
    public class FollowController {
    
    @Resource
    private IFollowService followService;

    //关注用户
    @PostMapping("/insertFollow")
    public Result insertFollow(@RequestBody Follow follow){
        follow.setUserId(Objects.requireNonNull(TokenUtils.getCurrentUser()).getId());
        return followService.insertFollow(follow);
    }

    //取消关注
    @DeleteMapping("/deleteFollow")
    public Result deleteFollow(@RequestParam Integer fouserId) {
        Follow follow = new Follow();
        follow.setUserId(Objects.requireNonNull(TokenUtils.getCurrentUser()).getId());
        follow.setFouserId(fouserId);
        return followService.removeFollow(follow);
    }

    //查找当前用户关注列表
    @GetMapping("/findFollowee")
    public Result findFollowee() {
        return Result.success(followService.findFollowee(Objects.requireNonNull(TokenUtils.getCurrentUser()).getId()));
    }


    //查找当前用户粉丝列表
    @GetMapping("/findFollower")
    public Result findFollower() {
        return Result.success(followService.findFollower(Objects.requireNonNull(TokenUtils.getCurrentUser()).getId()));
    }

    //查找其他用户粉丝列表
    @GetMapping("/findOtherFollower/{id}")
    public Result findOtherFollower(@PathVariable Integer id) {
        return Result.success(followService.findFollower(id));
    }
}

